package aulas.semana08.exemplosaula.livroautor;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class ConnectionFactory {

    public static Connection getConnection() throws SQLException, IOException, ClassNotFoundException{    
        String drive =  ConnectionFactory.getProp().getProperty("db.driver");
        String url =  ConnectionFactory.getProp().getProperty("db.url");
        String user =  ConnectionFactory.getProp().getProperty("db.user");
        String pwd =  ConnectionFactory.getProp().getProperty("db.pwd");
        Class.forName(drive);
        return DriverManager.getConnection(url, user, pwd);

    }
     private static Properties getProp() throws FileNotFoundException, IOException{
       Properties prop = new Properties();
       FileInputStream file = new FileInputStream("../Exemplo8/src/aulas/semana08/exemplosaula/livroautor/db.properties");
       prop.load(file);
       return prop;
   }
}
